<script type="text/javascript">
    $(document).ready(function () {

        $('form').submit(function (e) {
            e.preventDefault();
            var data = '&old_pass=' + $(this).find('.old_pass').val() +
                    '&pass=' + $(this).find('.pass').val() +
                    '&pass2=' + $(this).find('.pass2').val();
            $.ajax({
                url:'<?php echo base_url() . "changeProfile/changePW/"?>',
                type:'POST',
                data:data,
                success:function (data) {
                    obj = eval("(" + data + ")");
                    console.log(obj);
                    if (obj === "Ok") {
                        $('.reg_div h1').html('Zmena hesla úspešná!');
                        $('.forma').empty();
                        $(function () {
                            setTimeout(function () {
                                $('#facebox').hide();
                                $('.warn_comments').hide();
                                $('.warn_thumbs').hide();
                                $('.facebox_overlayBG').hide();
                                $('.facebox_overlay').hide();
                            }, 2000);
                        });
                    }
                    else if (obj === "bad_old_pw") {
                        if ($('.reg_error').html !== "") {
                            $('.reg_error').fadeOut(500);
                            $('.reg_error').fadeIn(500);
                        }
                        $('.reg_error').html('<span style="font-size:10px; color:red;">Incorrect current password!</span>');
                    }
                    else {
                        $('.reg_error').html("");
                        if (obj['pass'] === "") {
                            $('.pass_error').html('');
                        }
                        if (obj['pass2'] === "") {
                            $('.pass2_error').html('');
                        }
                        if (obj['pass'] !== "") {
                            if ($('.pass_error').html !== "") {
                                $('.pass_error').fadeOut(500);
                                $('.pass_error').fadeIn(500);
                            }
                            $('.pass_error').html('<span style="font-size:10px; color:red;">' + obj['pass'] + '</span>');
                        }
                        if (obj['pass2'] !== "") {
                            if ($('.pass2_error').html !== "") {
                                $('.pass2_error').fadeOut(500);
                                $('.pass2_error').fadeIn(500);
                            }
                            $('.pass2_error').html('<span style="font-size:10px; color:red;">' + obj['pass2'] + '</span>');
                        }
                    }
                }
            });
        });

    });
</script>

<div class="reg_div" style="text-align:center;">
    <h1>Zmena hesla</h1>
    <ul style="list-style: none;text-align: center;padding:3px;" class="forma">
        <?php echo form_open('changeProfile/submit');
        ?>
        <li class="reg_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'password', 'name' => 'old_pass', 'class' => 'old_pass', 'placeholder' => 'Old Password', 'autocomplete' => 'off')); ?>
        </li>
        <li>
            <?php echo form_input(array('type' => 'password', 'name' => 'pass', 'class' => 'pass', 'placeholder' => 'Password', 'autocomplete' => 'off')); ?>
        </li>
        <li class="pass_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'password', 'name' => 'pass2', 'class' => 'pass2', 'placeholder' => 'Password again...', 'autocomplete' => 'off')); ?>
        </li>
        <li class="pass2_error">
        </li>
        <li>
            <?php echo form_submit(array('type' => 'submit', 'value' => 'Potvrď zmeny!', 'class' => 'reg_button')); ?>
        </li>
        <?php echo form_close(); ?>

    </ul>

</div>